<?php
include 'header.php';
include 'constant.php';
include 'db_cred.php';
?>
<script type=text/javascript>
function validate_input()
{
  document.forms["main"]["user_name"].value = document.forms["main"]["user_name"].value.toLowerCase();
  var user_name = document.forms["main"]["user_name"].value;
  if (user_name == "")
  {
    alert ("Error : User Name must not be empty");
    return false;
  }

  var user_password = document.forms["main"]["user_password"].value;
  if (user_password == "")
  {
    alert ("Error : Current Password must not be empty");
    return false;
  }

  var fullname = document.forms["main"]["user_fullname"].value;
  if (fullname == "")
  {
    alert ("Error : Full name must not be empty");
    return false;
  }

  var user_phone = document.forms["main"]["user_phone"].value;
  var regexp = /^\d{10}$/;
  if (! regexp.test(user_phone))
  {
    alert ("Error : Phone Number must contain 10 digits only");
    return false;
  }
}
</script>
<?php
if (($_REQUEST['user_name'] != '') && ($_REQUEST['user_password'] != ''))
{
  # try and see if user already exist, if so then quit and no try to create user
  $query = "select user_name from user where user_name = '". $_REQUEST['user_name'] . "'";
  $result = mysql_query($query) or print('Query failed: ' . mysql_error());
  $row = mysql_fetch_assoc($result);
  if ($row['user_name'] == $_REQUEST['user_name'])
  {
    $_SESSION['registration_status'] = 'Error : User ' . $_REQUEST['user_name'] . ' already exists in the system';
  }
  else
  {
     $_SESSION['registration_status'] = 'Creating User ' . $_REQUEST['user_name'];
     $query = sprintf ("insert into user (user_name,user_password, user_fullname, user_phone, user_timezone) values ('%s','%s','%s','%d','%s')",$_REQUEST['user_name'],$_REQUEST['user_password'],$_REQUEST['user_fullname'],$_REQUEST['user_phone'],$_REQUEST['user_timezone']);
     $result = mysql_query($query) or ($_SESSION['registration_status'] = 'Error : ' . mysql_error());
#     $_SESSION['authorized_user'] = $_REQUEST['user_name'];
  }
}
?>
Please complete the following information:
<BR />
<BR />
<FORM NAME="main" ONSUBMIT="return validate_input()">
<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0>
<TR><TD>User Name</TD><TD WIDTH=5 /><TD><INPUT TYPE=TEXT NAME=user_name WIDTH=30 /></TD></TR>
<TR><TD>Password</TD><TD /><TD><INPUT TYPE=PASSWORD NAME=user_password WIDTH=30 /></TD></TR>
<TR><TD>Full Name</TD><TD WIDTH=5 /><TD><INPUT TYPE=TEXT NAME=user_fullname WIDTH=30 /></TD></TR>
<TR><TD>Phone Number</TD><TD WIDTH=5 /><TD><INPUT TYPE=TEXT NAME=user_phone WIDTH=30 /></TD></TR>
<TR><TD>Time Zone</TD><TD WIDTH=5 /><TD><select NAME=user_timezone WIDTH=30>
<OPTION VALUE="GMT">GMT (GMT)</OPTION>
<OPTION VALUE="UTC">UTC (GMT)</OPTION>
<OPTION VALUE="ECT">ECT (GMT+1:00)</OPTION>
<OPTION VALUE="EET">EET (GMT+2:00)</OPTION>
<OPTION VALUE="ART">ART (GMT+2:00)</OPTION>
<OPTION VALUE="EAT">EAT (GMT+3:00)</OPTION>
<OPTION VALUE="MET">MET (GMT+3:30)</OPTION>
<OPTION VALUE="NET">NET (GMT+4:00)</OPTION>
<OPTION VALUE="PLT">PLT (GMT+5:00)</OPTION>
<OPTION VALUE="IST">IST (GMT+5:30)</OPTION>
<OPTION VALUE="BST">BST (GMT+6:00)</OPTION>
<OPTION VALUE="VST">VST (GMT+7:00)</OPTION>
<OPTION VALUE="CTT">CTT (GMT+8:00)</OPTION>
<OPTION VALUE="JST">JST (GMT+9:00)</OPTION>
<OPTION VALUE="ACT">ACT (GMT+9:30)</OPTION>
<OPTION VALUE="AET">AET (GMT+10:00)</OPTION>
<OPTION VALUE="SST">SST (GMT+11:00)</OPTION>
<OPTION VALUE="NST">NST (GMT+12:00)</OPTION>
<OPTION VALUE="MIT">MIT (GMT-11:00)</OPTION>
<OPTION VALUE="HST">HST (GMT-10:00)</OPTION>
<OPTION VALUE="AST">AST (GMT-9:00)</OPTION>
<OPTION VALUE="PST">PST (GMT-8:00)</OPTION>
<OPTION VALUE="PNT">PNT (GMT-7:00)</OPTION>
<OPTION VALUE="MST">MST (GMT-7:00)</OPTION>
<OPTION VALUE="CST">CST (GMT-6:00)</OPTION>
<OPTION VALUE="EST">EST (GMT-5:00)</OPTION>
<OPTION VALUE="IET">IET (GMT-5:00)</OPTION>
<OPTION VALUE="PRT">PRT (GMT-4:00)</OPTION>
<OPTION VALUE="CNT">CNT (GMT-3:30)</OPTION>
<OPTION VALUE="AGT">AGT (GMT-3:00)</OPTION>
<OPTION VALUE="BET">BET (GMT-3:00)</OPTION>
<OPTION VALUE="CAT">CAT (GMT-1:00)</OPTION>
</select></TD></TR>

<TR><TD COLSPAN=3><FONT COLOR="RED"><?php print $_SESSION['registration_status'];?></FONT></TD></TR>
<TR><TD COLSPAN=3 ALIGN=CENTER><INPUT TYPE=SUBMIT VALUE="Create User" /><INPUT TYPE=BUTTON ONCLICK="location.href='/'" VALUE="Go to Main Page" />
</TD></TR>
</TABLE>
</FORM>
<BR />
<?php
include 'footer.php';
?>
